#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QDebug>
#include <QTextCodec>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(OnMyMsg()));
}

//Qt5简单例子和中文乱码问题
void MainWindow::OnMyMsg()
{
    qDebug()<<"test";
    qDebug()<<"test line";
    qDebug()<<endl;
    qDebug()<<"test hehe";
    //QMessageBox::information(this, QString::fromLocal8Bit("提示"), QStringLiteral("中文显示"));

    //自行处理中文
    QTextCodec * BianMa = QTextCodec::codecForName ( "UTF-8" );
    QMessageBox::information(this, "提示", BianMa->toUnicode("我要中文显示!"));

//    QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("中文提示"));
     QMessageBox::information(this,QString::fromUtf8("提示"), QString::fromUtf8("中文提示"));
     QString s1 = "汉语";
     QMessageBox::information(this, "提示", s1);
     QString s2("漢語");
     QMessageBox::information(this, "提示", s2);

     QString s3 = tr("中文");
     QMessageBox::information(this, "提示", s3);


     QString s5 = QString::fromUtf8("中文");
     QMessageBox::information(this, "提示", s5);
}

MainWindow::~MainWindow()
{
    delete ui;
}
